<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@taglib prefix="s" uri="/struts-tags"%> 
<%@include file="include.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    
    <link rel='shortcut icon' type='image/x-icon' href='../favicon.ico' />

    <title>管理界面</title>
<script src="js/metroui/js/jquery.dataTables.min.js"></script>
<script src="js/admin.js" charset="utf-8"></script>

  
</head>

<% 
String r=session.getAttribute("role").toString();

int roleid= Integer.valueOf(r); 
if (roleid!=1)
	response.sendRedirect("main.jsp");
%>



<body>
<s:i18n name="message"/>

    <div class="app-bar fixed-top darcula" data-role="appbar">
        <a class="app-bar-element branding">${tip}  ${nickname}</a>
        <span class="app-bar-divider"></span>
        <ul class="app-bar-menu">
            <li><a href="main.jsp"><s:text name="Home"/></a></li>
            <li >
                <a href="" class="dropdown-toggle"><s:text name="file"/></a>
                <ul class="d-menu" data-role="dropdown">
                    <li onclick="fileupload()"><a href="#"><s:text name="newfile"/></a></li>
                    <li class="divider"></li>
                    <li >
                        <a href="" class="dropdown-toggle"><s:text name="filelist"/></a>
                        <ul class="d-menu" data-role="dropdown">
                            <li onclick="load_home()"><a href="#"><s:text name="classfy"/></a></li>
                            <li onclick="library()"><a href="#"><s:text name="mylib"/></a></li>
                            <li onclick="load_share()"><a href="#"><s:text name="sharedfile"/></a></li>
                            <li class="divider"></li>
                            <li onclick="load_allfile()"><a href="#"><s:text name="downloadall"/></a></li>
                        </ul>
                    </li>
                </ul>
            </li>
            <li><a href="#"><s:text name="security"/></a></li>
            
            <li>
                <a href="" class="dropdown-toggle"><s:text name="help"/></a>
                <ul class="d-menu" data-role="dropdown">
                    
                    <li><a href="https://metroui.org.ua/"><s:text name="support"/></a></li>
                    <li class="divider"></li>
                    <li onclick="alert('2017 JAVAEE课程设计')"><a href="#"><s:text name="about"/></a></li>
                </ul>
            </li>
        </ul>

        <div class="app-bar-element place-right">
            <span class="dropdown-toggle"><span class="mif-cog"></span> 账户</span>
            <div class="app-bar-drop-container padding10 place-right no-margin-top block-shadow fg-dark" data-role="dropdown" data-no-close="true" style="width: 220px">
                <h2 class="text-light"><s:text name="settings"/></h2>
                <ul class="unstyled-list fg-dark">
                    <li onclick="load_info()"><a href="#" class="fg-white1 fg-hover-yellow"><s:text name="profile"/></a></li>
                    <li><a href="#" class="fg-white2 fg-hover-yellow"><s:text name="security"/></a></li>
                    <li><a href="Logout.jsp" class="fg-white3 fg-hover-yellow"><s:text name="exit"/></a></li>
                </ul>
            </div>
        </div>
    </div>

    <div class="page-content bg-white" style="height: 100%;">
        <div class="flex-grid no-responsive-future padding20 bg-white" style="height: 100%;">
           <div class="tabcontrol" data-role="tabcontrol" data-open-target="#frame_3_1">
                            <ul class="tabs">
                                <li class="active"><a href="#frame_3_1">用户登录管理</a></li>
                                <li class=""><a href="#frame_3_2">所有文件管理</a></li>
                                <li class=""><a href="#frame_3_3">管理文件分类</a></li>
                                <li class=""><a href="#frame_3_4">查看日志</a></li>
                            </ul>
                            <div class="frames">
                               <div class="frame bg-white" id="frame_3_1" style="display: block;">
                                
                <table class="table striped hovered dataTable border bordered" id="userTable" style="width:100%;">
                <thead>
                <tr>
                    <th class="text-center">用户ID</th>
                    <th class="text-center">用户名</th>
					<th class="text-center">用户昵称</th>
					<th class="text-center">注册时间</th>
					<th class="text-center">登录许可</th>
					
                </tr>
                </thead>

                <tbody>
                </tbody>
            </table>
</div>
                                <div class="frame bg-white" id="frame_3_2" style="display: none;">
                                <div class="input-control text" data-role="input" style="float:right;">
<input type="text" name="search" id="extra_search"><button class="button"><span class="mif-search"></span></button>
</div>
<table class="table striped hovered dataTable border bordered padding20" id="fileTable" style="width:100%;">
                <thead>
                <tr>
                    <th class="text-left">Fileid</th>
                    <th class="text-left">Filename</th>
					<th class="text-left">Uploadtime</th>
					<th class="text-left">Userid</th>
					<th class="text-left">操作</th>
					
					
                </tr>
                </thead>

                <tbody>
                </tbody>
            </table>
                                
                                


                            </div>
                            
                            
                            <div class="frame bg-white" id="frame_3_3" style="display: none;">
<div class="panel">
   
    <div class="heading">
        <span class="title">添加类</span>
    </div>

    <div class="content">
               
        <br/>
       <button id="show1"  class="button" >添加类</button>
                  <br/>
        <br/>
    </div>
</div>

<div class="panel">
    <div class="heading">
        <span class="title">管理类</span>
    </div>
    <div class="content">
    <div class="input-control select info">
       <select id="selectFileClass"></select>
       </div>
       
       <button id="del"  class="button danger">删除类</button><p id="delresult"></p>

       <div class="input-control text info">
   <input type="text" id="ren" >
   </div><button id="rn" class="button">修改类名</button><p id="result2"></p>
    </div>
</div>

   


<div data-role="dialog" data-close-button="true" data-overlay="true" data-overlay-color="op-dark"
 data-overlay-click-close="true" data-type="info"  id="crelib" class="padding10">
    <h1>添加类</h1>

	<div class="input-control text info">
   <input type="text" id="cln1" name="classname">
   </div>
   <button id='cre' class="button">创建</button>
   <p id="result1"></p>
   </div>
   
    

    
</div>
 <div class="frame bg-white" id="frame_3_4" style="display: block;">
 
 
 <table class="table striped hovered dataTable border bordered padding20" id="logTable1" style="width:100%;">
                <thead>
                <tr>
                    <th class="text-left">logid</th>
                    <th class="text-left">Login User</th>
                    <th class="text-left">Description</th>
					<th class="text-left">Operation Time</th>
					
					
					
                </tr>
                </thead>

                <tbody>
                </tbody>
            </table>

 </div>
                        </div>
           
        </div>
    </div>
</div>
 <script type="text/javascript">
 $(document).ready(function(){
	 
/*
 * ============================分割线======以下是表格操作===================================
*/	
	var table1=$("#userTable").DataTable({
		ajax:{
			url:"listuser.action"
			},
     
        	

    	"oLanguage": {
    		"sLengthMenu": "每页显示 _MENU_ 条记录",
    		"sZeroRecords": "抱歉， 没有找到",
    		"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条",
    		"sInfoEmpty": "没有数据",
    		"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
    		"oPaginate": {
    		"sFirst": "首页",
    		"sPrevious": "前一页",
    		"sNext": "后一页",
    		"sLast": "尾页"
    		},
    		"sZeroRecords": "没有检索到数据"
    	},
    	
    	
    columns: [ 
    	{data:"userid"},
    	
    	{data:"username"},
    	{data:"nickname"},
    	{data:"createTime",render:function(data){
    		
    		return UnixToDate(data);
    	}
    	},
    	
    	{data:"forbid",render:function(forbid){
    		var switcher="<label class='switch-original'><input type='checkbox' class='ck' ";
    			if(forbid==0)
    				switcher+="checked";
    			switcher+=">";
    			switcher+= "<span class='check'></label>"
    			switcher+="<input type='hidden' class='hi' value='"+forbid+"' >"
    		return switcher;
    		
    	}}
    	]

	 }
    );
    
    
	$("#userTable").on("click",".ck",function(){
		var f=$(this).parent().next(".hi").val();
		var tu=$(this).parent().parent().parent().children("td").get(0).innerHTML;
		alert(tu);
		if(f==1){
			$(this).parent().next(".hi").val(0);
		}else if(f==0)
			$(this).parent().next(".hi").val(1);
		
		$.post("forbiduser.action",{theuserid:tu,forbid:f},function(tip,status){
			$.Notify({
			    caption: '修改结果',
			    content: tip,
			    type: status
			});
		});
	});
		
/*
 * ===================================以上table1，以下table2=========================================
 */


	var table2=$("#fileTable").DataTable( {
        "processing": true,
        "ordering": false, 
        "searching":false,
        serverSide: true,
        ajax:{
			url:"listjson2.action"

			},
     


    	"oLanguage": {
    		"sLengthMenu": "每页显示 _MENU_ 条记录",
    		"sZeroRecords": "抱歉， 没有找到",
    		"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条",
    		"sInfoEmpty": "没有数据",
    		"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
    		"oPaginate": {
    		"sFirst": "首页",
    		"sPrevious": "前一页",
    		"sNext": "后一页",
    		"sLast": "尾页"
    		},
    		"sZeroRecords": "没有检索到数据"
    	},
    	
    	
    columns: [ 
    	{data:"fileid"},
    	
    	{data:"filename"},
    	
    	{data:"uploadtime.time",render:function(data){
    		
    		return UnixToDate(data);
    	}
    	},
    	{data:"userid"},
    	{"defaultContent":"<button class='button danger'>删除记录</button>"}
    	]

	 }
    );
    
    
	$("#fileTable").on("click",".danger",function(){
		var id=$(this).parent().parent().children("td").get(0).innerHTML; 
		alert(id);
		$.post("delfile.action",{fileid:id},function(tip,status){
			$.Notify({
			    caption: '结果',
			    content: tip,
			    type: status
			});
		});
		
	});
	
	
	/*
	*========================================割==============================================
	*
	*/
	
	$.get("fileclass.action", function(c, status) {
		
		for(var i=0;i<c.fileclass.fileclass.length;i++)
		$("#selectFileClass").append("<option value='"+c.fileclass.fileclass[i].classid+"'>"+c.fileclass.fileclass[i].classname+"</option>");
		
	});
	
	
	
	
	/*
	*========================================table4==查看登录日志============================================
	*
	*/	
	
	
	var table4=$("#logTable1").DataTable({
        "processing": true,
        "ordering": false, 
        "searching":false,
        serverSide: true,
		ajax:{
			url:"listLoginLog.action"
			},
     
        	

    	"oLanguage": {
    		"sLengthMenu": "每页显示 _MENU_ 条记录",
    		"sZeroRecords": "抱歉， 没有找到",
    		"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条",
    		"sInfoEmpty": "没有数据",
    		"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
    		"oPaginate": {
    		"sFirst": "首页",
    		"sPrevious": "前一页",
    		"sNext": "后一页",
    		"sLast": "尾页"
    		},
    		"sZeroRecords": "没有检索到数据"
    	},
    	
    	
    columns: [ 
    	{data:"logid"},
    	
    	{data:"username"},
    	{data:"description"},
    	{data:"time.time",render:function(data){
    		
    		return UnixToDate(data);
    	}
    	}
    	
    	
    	]

	 }
    );
	
	
	
/*
 * ============================分割线======以下是按钮操作===================================
 */	
		
		
	$("#show1").click(function(){
		metroDialog.open('#crelib');
	});	
		
	$("#cre").click(function(){
		var cname=$("#cln1").val();
		//alert(cname);
		$.post("addclass.action",{classname:cname},function(tip,status){
			$.Notify({
			    caption: '添加结果',
			    content: tip,
			    type: status
			});
		});
	});		
	$("#del").click(function(){
		var d=$("#selectFileClass").val();
		$.post("delclass.action",{classid:d},function(tip,status){
			$.Notify({
			    caption: '删除结果',
			    content: tip,
			    type: status
			});
		});
	});	
	$("#rn").click(function(){
		var cid=$("#selectFileClass").val();
		var cn=$("#ren").val();
		alert(cn);
		$.post("renameclass.action",{classid:cid,classname:cn},function(tip,status){
			$.Notify({
			    caption: '修改结果',
			    content: tip,
			    type: status
			});
		});
	});
/*
 * ==================================表2的搜索操作===============================================
 */	
   	$("#extra_search").blur(function(){
		
   		ChangeSearch();      		    
	});
   	$("#extra_search").focus(function(){
   		$("#extra_search").keydown(function(e){ 
   			if(e.keyCode==13){ 
   				ChangeSearch();
   			}
   			
   		});
   		
   	});
	//关键字搜索
    function ChangeSearch(){
   		   var ss=$("#extra_search").val();
   			table2.ajax.url(encodeURI("listjson2.action?search="+ss)).load();
   	   }
		
 });
 
 
 
 
 function UnixToDate(unixTime) {
     var date=new Date(unixTime);
     Y = date.getFullYear() + '-';
     M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
     D = date.getDate() + ' ';
     h = date.getHours() + ':';
     m = date.getMinutes() + ':';
     s = date.getSeconds(); 
 	
     return Y+M+D+h+m+s;
 }
 

 
 </script>   
                            
</body>
</html>